package com.sh.dc.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;

public class CodeGenerator {


    public static void main(String[] args) {
        String dbUrl = "jdbc:postgresql://pgm-uf63m15yrn55v046to.pg.rds.aliyuncs.com:5432/sh_dc_res?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B";
        String dbUsername = "postgres";
        String dbPassword = "SHDEV2024@postgres";
        String projectDir = "/Users/luotao/Desktop/上航/code/sh-distributed-computing-backend";
        FastAutoGenerator.create( dbUrl, dbUsername, dbPassword)
                .globalConfig(builder -> {
                    builder.author("zhenlan") // 设置作者
                            .outputDir(projectDir + "/src/main/java"); // 指定输出目录
                })
                .dataSourceConfig(builder ->
                        builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                            return typeRegistry.getColumnType(metaInfo);
                        })
                )
                .packageConfig(builder ->
                        builder.parent("com.sh.dc") // 设置父包
                                .entity("entity")
                                .mapper("mapper")
                                .service("service")
                                .serviceImpl("service.impl")
                                .xml("mapper")  // 生成xml文件后，需要手动copy到resources/mappers下
                )
                .strategyConfig(builder -> {
                    builder.addInclude("t_task_log") // 设置需要生成的表名
                            .addTablePrefix("t_")
                            .entityBuilder()
                            .enableLombok() // 启用 Lombok
                            .enableTableFieldAnnotation() // 启用字段注解
                            .controllerBuilder()
                            .enableRestStyle(); // 启用 REST 风格
                })
                .execute();
    }

}
